package com.example.my_flea_street.Mapper;


import com.example.my_flea_street.bean.Info;
import com.example.my_flea_street.bean.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface UserMapper {

    @Select("SELECT b.id ,b.release_time,b.text,b.pic,b.category,b.key,b.is_settled,b.is_banned,b.user_id,a.name,a.sex,a.head FROM user a,information b WHERE a.id=b.user_id ORDER BY release_time")
    Page<Info> getAllUser();

    @Select("select * from user where id=#{id}")
    User getUserById(@Param("id") int id);

    @Select("select * from user where phone=#{phone}")
    User getUserByPhone(@Param("phone") String phone);

    @Insert("insert into user(name,phone,age,sex,head,school,institute,introduction) values(#{name},#{phone},#{age},#{sex},#{head},#{school},#{institute},#{introduction})")
    @Options(useGeneratedKeys = true)
    int register(@Param("name") String name, @Param("phone") String phone, @Param("age") int age, @Param("sex") String sex,
                 @Param("head") String head, @Param("school") String school, @Param("institute") String institute,
                 @Param("introduction") String introduction);

    @Select("select password from login where phone=#{phone}")
    String getPassword(@Param("phone") String phone);
    @Select("select head from user where id=#{id}")
    String getHead(@Param("id") int id);

    @Update("update user set name=#{name},head=#{head},age=#{age}" +
            ",institute=#{institute},introduction=#{introduction},school=#{school} where id=#{id}")
    int editUser(@Param("id") int id,@Param("name")  String name,@Param("head")  String head,
                 @Param("age") int age, @Param("institute") String institute,
                 @Param("introduction")  String introduction,@Param("school")  String school);
}
